<?
	require_once(__DIR__ . '/../inc/functions.php');
	$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
	switch($action){
		case 'POST':
			break;
		default: //	GET - Index & Details
			$conn = GetConnection();
			if(isset($_REQUEST['q']))
				$q = $_REQUEST['q'];
			if(isset($_REQUEST['term']))
				$q = $_REQUEST['term'];
			
			if(isset($q))
				$results = $conn->query("SELECT distinct city, state FROM US_Zip_Codes WHERE city LIKE '%$q%' OR state LIKE '%$q%' LIMIT 10");			
			else
				$results = $conn->query('SELECT * FROM US_Zip_Codes ');

			$arr = array();
			while($row = $results->fetch_assoc())
				$arr[] = $row['city'] . ', ' . $row['state'];
				echo json_encode( $arr);
			break;
	}